import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/components/Home.vue'
import Login from '@/components/user/Login.vue'
import Register from '@/components/user/Register.vue'
import InterfaceSearch from '@/components/interface/InterfaceSearch.vue'
import InterfaceOnlineInvoke from '@/components/interface/InterfaceOnlineInvoke.vue'
import UserProfile from '@/components/user/UserProfile.vue'
import UserDashboard from '@/components/user/UserDashboard.vue'
import PointsBalance from '@/components/user/userDashboard/PointsBalance.vue'
import UserDashboardWelcome from '@/components/user/userDashboard/UserDashboardWelcome.vue'
import TokenSecret from '@/components/user/userDashboard/TokenSecret.vue'
import ApiAccessStatistics from '@/components/user/userDashboard/ApiAccessStatistics.vue'
import AdminDashboard from '@/components/user/AdminDashboard.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/about',
      name: 'about',
      // 路由级代码分割
      // 这将为该路由生成一个单独的块（About.[hash].js）
      // 当路由被访问时懒加载。
      component: () => import('../views/AboutView.vue')
    },
    {
      path: '/home',
      name: 'Home',
      component: Home
    },
    {
      path: '/user/login',
      component: Login
    },
    {
      path: '/user/profile',
      name: 'UserProfile',
      component: UserProfile
    },
    {
      path: '/user/register',
      component: Register
    },
    {
      path: '/interface/search',
      component: InterfaceSearch
    },
    {
      path: '/interface/onlineInvoke/:interfaceId',
      name: 'OnlineInvoke',
      component: InterfaceOnlineInvoke
    },
    {
      path:"/user/userDashboard",
      component:UserDashboard
    },
    {
      path:"/user/userDashboard/pointsBalance",
      component:PointsBalance
    },
    {
      path:"/user/userDashboard/userDashboardWelcome",
      component:UserDashboardWelcome
    },
    {
      path:"/user/userDashboard/tokenSecret",
      component:TokenSecret
    },
    {
      path:"/user/userDashboard/apiAccessStatistics",
      component:ApiAccessStatistics
    },
    {
      path:"/admin/adminDashboard",
      component:AdminDashboard
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else if (to.hash) {
      return {
        el: to.hash,
        behavior: 'smooth',
      }
    } else {
      return { top: 0 }
    }
  }
})

export default router
